package cn.com.huzo.repository.tech.impl;

import cn.com.huzo.model.entities.tech.ProductBomLinesEntity;
import cn.com.huzo.repository.tech.ProductBomLinesRepository;
import huzofw.repository.impl.GenericRepositoryImpl;
import huzofw.repository.impl.MyBatisDaoUtils;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.stereotype.Repository;

/**
 * EBOM数据访问对象。
 *
 * @author 吴旭
 */
@Repository("ProductBomLinesRepository")
public class ProductBomLinesRepositoryImpl extends GenericRepositoryImpl<ProductBomLinesEntity, String>
        implements ProductBomLinesRepository {

    private final String namespace = "cn.com.huzo.repository.tech.ProductBomLinesRepository";

    /**
     * 构造函数,设置the instance to ProductRepositoryImpl.class.
     */
    public ProductBomLinesRepositoryImpl() {
        super(ProductBomLinesEntity.class);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public List<ProductBomLinesEntity> fetchByHeaderId(Long headerId) {
        return getSqlSession().selectList(MyBatisDaoUtils.getMapperQueryId(
                namespace, "fetchByHeaderId"), headerId);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer batchInsert(List<ProductBomLinesEntity> itemList) {
        return getSqlSession().insert(MyBatisDaoUtils.getMapperQueryId(
                namespace, "batchInsert"), itemList);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer batchUpdate(List<ProductBomLinesEntity> itemsList) {
        return getSqlSession().update(MyBatisDaoUtils.getMapperQueryId(
                namespace, "batchUpdate"), itemsList);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer updateLinesByMaterialId(String linesId, Long materialId) {
        Map<String, Object> criterion = new HashMap();
        criterion.put("LinesId", linesId);
        criterion.put("MaterialId", materialId);

        return getSqlSession().update(MyBatisDaoUtils.getMapperQueryId(
                namespace, "updateLinesByMaterialId"), criterion);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer delete(String key) {
        return getSqlSession().delete(MyBatisDaoUtils.getMapperQueryId(
                namespace, "delete"), key);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer batchDelete(List<ProductBomLinesEntity> itemList) {
        return getSqlSession().delete(MyBatisDaoUtils.getMapperQueryId(
                namespace, "batchDelete"), itemList);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer batchClearLinesProductBom(List<ProductBomLinesEntity> itemList) {
        return getSqlSession().delete(MyBatisDaoUtils.getMapperQueryId(
                namespace, "batchClearLinesProductBom"), itemList);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer importLinesFromOtherBom(Long headerId, Long importedBomHeaderId, Long createdBy, Long updatedBy) {
        Map<String, Object> criterion = new HashMap();
        criterion.put("HeaderId", headerId);
        criterion.put("ImportedBomHeaderId", importedBomHeaderId);
        criterion.put("CreatedBy", createdBy);
        criterion.put("UpdatedBy", updatedBy);

        return getSqlSession().insert(MyBatisDaoUtils.getMapperQueryId(
                namespace, "importLinesFromOtherBom"), criterion);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer insertFromClipboard(Long headerId, String copiedLinesId, Long materialId,
            Long uomId, String specification, Integer orderNo, Long createdBy, Long updatedBy) {
        Map<String, Object> criterion = new HashMap();
        criterion.put("HeaderId", headerId);
        criterion.put("CopiedLinesId", copiedLinesId);
        criterion.put("MaterialId", materialId);
        criterion.put("UomId", uomId);
        criterion.put("Specification", specification);
        criterion.put("OrderNo", orderNo);
        criterion.put("CreatedBy", createdBy);
        criterion.put("UpdatedBy", updatedBy);

        return getSqlSession().insert(MyBatisDaoUtils.getMapperQueryId(
                namespace, "insertFromClipboard"), criterion);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer clearImportedBomLinesId(Long headerId) {
        return getSqlSession().update(MyBatisDaoUtils.getMapperQueryId(
                namespace, "clearImportedBomLinesId"), headerId);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer resetLinesOrder(Long headerKey) {
        return getSqlSession().update(MyBatisDaoUtils.getMapperQueryId(
                namespace, "resetLinesOrder"), headerKey);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer updateLinesOrder(List<ProductBomLinesEntity> itemsList) {
        return getSqlSession().update(MyBatisDaoUtils.getMapperQueryId(
                namespace, "updateLinesOrder"), itemsList);
    }
}
